;
(function() {
	var skill = {
		save: function() {
			this._id && db.update(config.dbname.busEmployees, this._id, this);
		},
		destroy: function() {
			db.remove(config.dbname.busEmployees, this._id);
		},
		setInfo: function(info) {
			// 描述信息
			info.name = String(info.name || "").trim();
			info.pwd = String(info.pwd || "").trim();
			info.email = String(info.email || "").trim();
			info.mobile_phone = String(info.mobile_phone || "").trim();
			info.perms = info.perms instanceof Array ? $Array.clearNull(info.perms.map(function(item) {
				return typeof item == "string" ? item : null
			})) : [];
			console.log(info);
			if (!info.name) {
				throwCusError("子账号名不可为空")
			}
			if (!helper.name(info.name, "子账号名")) {
				throwCusError("子账号名过长");
			};
			if (!info.pwd) {
				throwCusError("子账号密码不可为空")
			}
			if (info.email ? !helper.isEmail(info.email) : false) {
				throwCusError("邮箱格式有误")
			}
			if (info.mobile_phone ? !helper.phone(info.mobile_phone) : false) {
				throwCusError("邮箱格式有误")
			}

			/*设定*/
			this.name = info.name;
			this.pwd = info.pwd; //明文存储，管理员可控
			info.email = info.email;
			info.mobile_phone = info.mobile_phone;
			this.perms = info.perms;

			/*保存*/
			this.save();
		},
		checkPassword: function(pwd) {
			console.log(this.pwd, pwd);
			return this.pwd === pwd;
		}
	}
	module.exports = skill;

	var db = require("../db/index");
	var GoodsCon = require("../goods/_con");
	var UserCon = require("../../core/user/_con");
	var BusCon = require("../../core/bus/_con");
	var AchCon = require("../ach/_con");
	var ClassifyCon = require("../bus.classify/_con");
	var TagCon = require("../bus.tag/_con");
	var LeagueCon = require("../league/_con");
	var BuffCon = require("../buff/_con");
	var BusUserBindCon = require("../bus_user_bind/_con");
	var BusGuideCon = require("../bus.guide/_con");
	var BusEmployeesCon = require("../bus.employees/_con");
	var CommentCon = require("../comment/_con");
	var config = require("../_include/config");
	var data_cut = require("../_include/data_cut");
	var helper = require("../_include/helper");
	var md5 = require("../_include/md5");
	var $Object = require("../_include/$.Object");
	var $Array = require("../_include/$.Array");
}());